home *** CD-ROM | disk | FTP | other *** search
/ System Booster / System Booster.iso / Archives / ARexxTools / larp145.lha / LARP / subs.c < prev   
Encoding:
C/C++ Source or Header  |  1993-06-05  |  3.9 KB  |  167 lines

  1. /* subs.c - originally modified from a designer produced file - designer (c) William Connor
  2.  */
  3.  
  4. #include "defs.h"
  5.  
  6. ULONG BevelTags[] = 
  7.     {
  8.     GTBB_Recessed, TRUE,
  9.     GT_VisualInfo, 0,
  10.     TAG_DONE
  11.     };
  12.  
  13. struct Window *Win0 = NULL;
  14. APTR Win0VisualInfo;
  15. UWORD Win0ZoomInfo[4] = { 300, 20, 200, 22 };
  16.  
  17. struct TextAttr topazattr = { (STRPTR)"topaz.font", 8, 0, 65 };
  18. struct TextFont *textfont;
  19.  
  20. struct Library *DiskfontBase = NULL;
  21. struct Library *GadToolsBase = NULL;
  22. struct GfxBase *GfxBase = NULL;
  23. struct IntuitionBase *IntuitionBase = NULL;
  24. unsigned char *LARP_pubscreen = NULL;
  25.  
  26. void RendWindowWin0( struct Window *Win )
  27. {
  28.     UWORD offx = Win->BorderLeft;
  29.     UWORD offy = Win->BorderTop;
  30.     if (Win != NULL) 
  31.     {
  32.         SetAPen(Win->RPort, 0);
  33.         RectFill(Win->RPort, offx+1, offy+1, Win->Width-19, Win->Height-Win->BorderBottom-1);
  34.         DrawBevelBoxA( Win->RPort, 4+offx,3+offy,Win->Width-offx-26,Win->Height-offy-Win->BorderBottom-6, (struct TagItem *) &BevelTags[0]);
  35.     }
  36. }
  37.  
  38. int OpenWindowWin0( void )
  39. {
  40.     struct Screen *Scr;
  41.     UWORD offx, offy;
  42.     if (Win0 == NULL)
  43.     {
  44.     if (NULL != (Scr = LockPubScreen(LARP_pubscreen)))
  45.     {
  46.         offx = Scr->WBorLeft;
  47.         offy = Scr->WBorTop + Scr->Font->ta_YSize+1;
  48.         Win0ZoomInfo[3] = offy + 22;
  49.         if (NULL != ( Win0VisualInfo = GetVisualInfoA( Scr, NULL)))
  50.         {
  51.             if (NULL != (Win0 = OpenWindowTags( NULL, WA_Left, 300,
  52.                             WA_Top, 20,
  53.                             WA_Width, 300+offx,
  54.                             WA_Height, 148+offy+Scr->WBorBottom,
  55.                             WA_Title, VSTRING,
  56.                             WA_MinWidth, offx+200,
  57.                             WA_MinHeight, offy+22,
  58.                             WA_MaxWidth, 65535,
  59.                             WA_MaxHeight, 65535,
  60.                             WA_SizeGadget, TRUE,
  61.                             WA_DragBar, TRUE,
  62.                             WA_DepthGadget, TRUE,
  63.                             WA_CloseGadget, TRUE,
  64.                             WA_Activate, TRUE,
  65.                             WA_SmartRefresh, TRUE,
  66.                             WA_AutoAdjust, TRUE,
  67.                             WA_Zoom, Win0ZoomInfo,
  68.                             WA_CustomScreen, Scr,
  69.                             WA_IDCMP,IDCMP_NEWSIZE|IDCMP_CLOSEWINDOW,
  70.                             TAG_END)))
  71.             {
  72.                 UnlockPubScreen( LARP_pubscreen, Scr);
  73.                 BevelTags[3] = (ULONG)Win0VisualInfo;
  74.                 textfont = OpenDiskFont( &topazattr);
  75.                 if (textfont == NULL)
  76.                 {
  77.                     textfont = OpenFont( &topazattr);
  78.                     if(textfont == NULL)
  79.                     {
  80.                         topazattr.ta_Name = (STRPTR)"topaz.font";
  81.                         topazattr.ta_YSize = 8;
  82.                         textfont = OpenFont( &topazattr);
  83.                     }
  84.                 }
  85.                 SetFont(Win0->RPort, textfont);
  86.                 RendWindowWin0( Win0 );
  87.                 if(LARP_pubscreen != NULL && (status & QUIET) == FALSE)
  88.                     ScreenToFront(Scr);
  89.                 return( 0L );
  90.             }
  91.             FreeVisualInfo( Win0VisualInfo );
  92.         }
  93.         UnlockPubScreen( LARP_pubscreen, Scr);
  94.     }
  95.     }
  96.     else
  97.     {
  98.     WindowToFront(Win0);
  99.     ActivateWindow(Win0);
  100.     return( 0L );
  101.     }
  102.     return( 1L );
  103. }
  104.  
  105. void CloseWindowWin0( void )
  106. {
  107.     if (Win0 != NULL)
  108.     {
  109.         CloseWindowSafely( Win0);
  110.         Win0 = NULL;
  111.         if(Win0VisualInfo!=0)
  112.         {
  113.             FreeVisualInfo( Win0VisualInfo);
  114.         }
  115.     }
  116. }
  117.  
  118. int OpenLibs( void )
  119. {
  120. if ( NULL != (DiskfontBase = OpenLibrary("diskfont.library" , 36)))
  121.     if ( NULL != (GadToolsBase = OpenLibrary("gadtools.library" , 37)))
  122.         if ( NULL != (GfxBase = (struct GfxBase * )OpenLibrary("graphics.library" , 37)))
  123.             if ( NULL != (IntuitionBase = (struct IntuitionBase * )OpenLibrary("intuition.library" , 37)))
  124.                 return( 0L );
  125. CloseLibs();
  126. return( 1L );
  127. }
  128.  
  129. void CloseLibs( void )
  130. {
  131. if (NULL != DiskfontBase )
  132.     CloseLibrary( DiskfontBase );
  133. if (NULL != GadToolsBase )
  134.     CloseLibrary( GadToolsBase );
  135. if (NULL != GfxBase )
  136.     CloseLibrary( ( struct Library * )GfxBase );
  137. if (NULL != IntuitionBase )
  138.     CloseLibrary( ( struct Library * )IntuitionBase );
  139. }
  140.  
  141. void StripIntuiMessages( struct MsgPort *mp, struct Window *win)
  142. {
  143. struct IntuiMessage *msg;
  144. struct Node *succ;
  145. msg = (struct IntuiMessage *)mp->mp_MsgList.lh_Head;
  146. while (succ = msg->ExecMessage.mn_Node.ln_Succ)
  147.     {
  148.     if (msg->IDCMPWindow == win)
  149.         {
  150.         Remove((struct Node *)msg);
  151.         ReplyMsg((struct Message *)msg);
  152.         }
  153.     msg = (struct IntuiMessage *)succ;
  154.     }
  155. }
  156.  
  157. void CloseWindowSafely( struct Window *win)
  158. {
  159.     CloseFont(textfont);
  160.     Forbid();
  161.     StripIntuiMessages( win->UserPort, win);
  162.     win->UserPort = NULL;
  163.     ModifyIDCMP( win, 0L);
  164.     Permit();
  165.     CloseWindow( win);
  166. }
  167.